#include<iostream>
#include<unistd.h>
#include<stdio.h>
#include<sys/types.h>
using namespace std;

int main(){
    //通过系统调用创建进程
    
    //cout<<"before: only one line"<<endl;
    //fork();
    //cout<<"after: only one line"<<endl;
    

    cout<<"begin:pocoess,pid:"<<getpid()<<" "<<"ppid:"<<getppid()<<endl;

    pid_t id =fork();
    if(id==0){
        //子进程
        while(1){
            cout<<"child process,pid:"<<getpid()<<" "<<"ppid:"<<getppid()<<endl;
            sleep(1);
        }
    }
    else if(id > 0){
        //父进程
        while(1){
            cout<<"parent process,pid:"<<getpid()<<" "<<"ppid:"<<getppid()<<endl;
            sleep(1);
        }
    }
    else{
        //
    }




    //标识符
    //pid_t pid=getpid();
    //pid_t ppid=getppid();
    //while(1){
    //    cout<<"I am a process, my pid is:"<<pid<<"parent pid is:"<<ppid<<endl;
    //    sleep(10);
    //}



    return 0;
}
